/**
 * Project Name:PayOrder.java
 * File Name:PayOrder.java
 * Date:2018/7/28 下午5:19
 * Copyright (c) 2018, zhang.xiangyu@foxmail.com All Rights Reserved.
*/
package com.meatball.base.pay.order.model;

import com.alibaba.fastjson.annotation.JSONField;
import com.alipay.api.internal.util.StringUtils;
import com.meatball.utils.DateUtil;
import com.meatball.vo.Pagetag;
import lombok.Data;

import java.util.Date;

/**
 * @Title: PayOrder.java
 * @Description: todo(订单)
 * @Author 張翔宇
 * @Date 2018/7/28 下午5:19
 * @Version V1.0
 */
@Data
public class PayOrder extends Pagetag {
    /**
     * 主键
     */
    @JSONField()
    private Long id;

    /**
     * 订单编号
     */
    private String outTradeNo;

    /**
     * 订单名称
     */
    private String orderName;

    /**
     * 总金额
     */
    private Long totalAmount;
    /**
     * 金额展示，单位：元
     */
    private Double totalAmountText;

    /**
     * 订单来源
     */
    private String orderSource;

    /**
     * 訂單狀態(0：待支付，1：已支付，2：已取消，3：已退款，4：已失效，5：支付金额与订单金额不符)
     */
    @JSONField(serialize = false)
    private Integer orderStatus;
    private String orderStatusText;

    /**
     * 创建时间
     */
    @JSONField(serialize = false)
    private Date createTime;
    private String createTimeText;

    /**
     * 更新时间
     */
    @JSONField(serialize = false)
    private Date updateTime;

    /**
     * vo base64格式二维码
     */
    private String qrCode;

    /**
     * vo 查询时间范围
     */
    @JSONField(serialize = false)
    private String timeHorizon;
    private String startDate;
    private String endDate;


    public void setCreateTime(Date createTime) {
        // 设置前端显示时间
        this.createTimeText = DateUtil.getTime(createTime);
        this.createTime = createTime;
    }

    public void setTotalAmount(Long totalAmount) {
        this.totalAmountText = Double.valueOf(totalAmount) /100;
        this.totalAmount = totalAmount;
    }

    public void setOrderStatus(Integer orderStatus) {
        switch (orderStatus) {
            case 1:
                this.orderStatusText = "已支付";
                break;
            case 2:
                this.orderStatusText = "已取消";
                break;
            case 3:
                this.orderStatusText = "已退款";
                break;
            case 4:
                this.orderStatusText = "已失效";
                break;
            case 5:
                this.orderStatusText = "支付金额与订单金额不符";
                break;
            default:
                this.orderStatusText = "待支付";
                break;
        }
        this.orderStatus = orderStatus;
    }

    public void setTimeHorizon(String timeHorizon) {
        if(StringUtils.areNotEmpty(timeHorizon)) {
            String[] date = timeHorizon.split(" - ");
            this.startDate  = date[0];
            this.endDate = date[1];
        }
        this.timeHorizon = timeHorizon;
    }
}